#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : xuexiaohua
# @time    : 2025/8/20 13:58
# @function: the script is used to do something.
# @version :
import json
import os
import yaml

from netPan123.conftest import PROJECT_ROOT_DIR, USER_File_PATH


def get_urls():
    '''
    从域名与路由配置文件中读取数据
    :return:
    '''
    with open(os.path.join(PROJECT_ROOT_DIR, 'configs', 'urls.yaml'), 'r', encoding='utf-8') as file:
        return yaml.safe_load(file)

def get_url_by_key(key):
    '''
    根据key获取url
    :param key:
    :return:
    '''
    urls_dict = get_urls()
    url = urls_dict["domain"] + urls_dict["module"][key]
    return url

def write_key(content, mode="a"):
    '''
    执行中数据写入文件
    :param filepath: 操作文件路径
    :param mode: 默认为追加模式，除非特殊指定
    :param content: 写入内容
    :return:
    '''
    with open(os.path.join(USER_File_PATH, 'userData.yaml'), mode, encoding='utf-8') as file:
        # if isinstance(content, dict):
        #     for key, value in content.items():
        #         file.write(key + ": ")
        #         file.write(str(value) + "\n")
        # else:
        #     file.write(content + "\n")
        file.write(yaml.safe_dump(content))

def get_key(key):
    with open(os.path.join(USER_File_PATH, 'userData.yaml'), "r", encoding='utf-8') as file:
        return yaml.safe_load(file)[key]


if __name__ == '__main__':
    # print(get_url_by_key("sign_in"))
    # write_key("aaa", mode="w")
    print(type(get_key("headers")))